﻿using System;
namespace Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="dokumendidVastusIseType", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(DokumendidVastusIseType))]
    public class DokumendidVastusIseTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDokumendidVastusIseType clazz;
        
        public DokumendidVastusIseTypeSerializer(IDokumendidVastusIseType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("paring");
            if (clazz.Paring!=null) {
                global::Xtee.Core.SerializationMetadata metaParing = this.GetMetaData(clazz.Paring);
                Writer.WriteTypeAttribute(metaParing.TypeQualifiedName.Namespace, metaParing.TypeQualifiedName.Name);
                metaParing.NewSerializer(clazz.Paring).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Paring");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("keha");
            if (clazz.Keha!=null) {
                global::Xtee.Core.SerializationMetadata metaKeha = this.GetMetaData(clazz.Keha);
                Writer.WriteTypeAttribute(metaKeha.TypeQualifiedName.Namespace, metaKeha.TypeQualifiedName.Name);
                metaKeha.NewSerializer(clazz.Keha).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Keha");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="paring") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>dokumendidVastusIseType>paring");
                }
                global::Xtee.Core.SerializationMetadata metaParing = this.GetMetaData<global::Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr.IDokumendidParingType>(Reader, "dokumendidParingType", "http://producers.ehr.xtee.riik.ee/producer/ehr");
                clazz.Paring = metaParing.NewEntity<global::Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr.IDokumendidParingType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("paring");
                    metaParing.NewSerializer(clazz.Paring).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>dokumendidVastusIseType>paring", Reader.LocalName);
            }
            if (Reader.LocalName=="keha") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>dokumendidVastusIseType>keha");
                }
                global::Xtee.Core.SerializationMetadata metaKeha = this.GetMetaData<global::Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr.IDokumendidVastusType>(Reader, "dokumendidVastusType", "http://producers.ehr.xtee.riik.ee/producer/ehr");
                clazz.Keha = metaKeha.NewEntity<global::Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr.IDokumendidVastusType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("keha");
                    metaKeha.NewSerializer(clazz.Keha).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>dokumendidVastusIseType>keha", Reader.LocalName);
            }
        }
    }
}
